﻿using JetBrains.Annotations;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Validation;

namespace TenantManagement;

[Index(nameof(Value))]
[Index(nameof(TenantId), nameof(Name), IsUnique = true)]
public class TenantDomain : Entity<Guid>
{
    [Key, Column(Order = 0)]
    public virtual Guid TenantId { get; protected set; }

    [Key, Column(Order = 1)]
    [NotNull]
    [Required]
    [DynamicMaxLength(typeof(TenantDomainConsts), nameof(TenantDomainConsts.MaxNameLength))]
    public virtual string Name { get; protected set; }

    [NotNull]
    [Required]
    [DynamicMaxLength(typeof(TenantDomainConsts), nameof(TenantDomainConsts.MaxValueLength))]
    public virtual string Value { get; protected set; }

    protected TenantDomain()
    {

    }

    public TenantDomain(Guid id, Guid tenantId, [NotNull] string name, [NotNull] string value)
    {
        Id = id;
        TenantId = tenantId;
        Name = Check.NotNullOrWhiteSpace(name, nameof(name), TenantDomainConsts.MaxNameLength);
        SetValue(value);
    }

    public virtual void SetValue([NotNull] string value)
    {
        Value = Check.NotNullOrWhiteSpace(value, nameof(value), TenantDomainConsts.MaxValueLength);
    }
}
